<template>
  <div>
    <city-header></city-header>
    <search></search>
    <city-list :cities="cities" :hotCities="hotCities" :clickKey="clickKey"></city-list>
    <city-alphabet :cities="cities" @goToItem="handleAlphabetClick"></city-alphabet>
  </div>
</template>

<script>

import CityHeader from './components/CityHeader.vue'
import Search from './components/Search.vue'
import CityList from './components/CityList.vue'
import CityAlphabet from './components/Alphabet.vue'
import axios from 'axios'
export default {
  components: {
    CityAlphabet,
    CityList,
    Search,
    CityHeader},
  name: 'City',

  data: function () {
    return {
      cities: {},
      hotCities: [],
      clickKey: ''
    }
  },
  methods: {
    getData: function () {
      axios.get('/api/city.json').then(this.handleAjax)
    },
    handleAlphabetClick: function (key) {
      this.clickKey = key
    },
    handleAjax: function (res) {
      res = res.data
      if (res.ret && res.data) {
        this.cities = res.data.cities
        this.hotCities = res.data.hotCities
      }
    }
  },
  mounted: function () {
    this.getData()
  }
}
</script>

<style></style>
